package com.example.exam1.util;

import java.sql.*;

/**
 * @author Deepwind
 */
public class JDBCUtils {
    private static final String URL = "jdbc:mysql://150.109.6.243:3306/exam";
    private static final String USER = "exam";
    private static final String PASSWORD = "root";
    private static final String driver = "com.mysql.cj.jdbc.Driver";

    public static Connection getConn() throws ClassNotFoundException, SQLException {
        Class.forName(driver);
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }

    public static void release(ResultSet rs, PreparedStatement ps, Connection conn) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
